﻿using MessagePack;

using StudentAgeSaveEditor.Models;
using System.Diagnostics;
using System.IO;

namespace StudentAgeSaveEditor.SaveData
{
    internal class DataMrg
    {
        public static (ISaveData, bool) Load(string _directory, string _filename)
        {
            string text = _directory + _filename;
            if (File.Exists(text))
            {
                using FileStream fileStream = File.Open(text, FileMode.Open);
                var saveDict = MessagePackSerializer.Deserialize<Dictionary<string, ISaveLoadValue>>(fileStream, null, default);
                Debug.WriteLine("Dump Finsh: " + text);
                return (ISaveData.Init(saveDict), true);
            }
            else
            {
                Debug.WriteLine("Load Error: 存档不存在 " + text);
                return (new ISaveData(), false);
            }
        }
    }
}
